x86_emulate: Emulate FNINIT, FNSTCW, FNSTSW x87 instructions.
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 23 Jan 2008 14:30:29 +0000 (14:30 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 23 Jan 2008 14:30:29 +0000 (14:30 +0000)
Provide new hook ->load_fpu_ctxt() to ensure emulated environment's
FPU state is loaded onto the local processor.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
xen/arch/x86/x86_emulate.c
xen/include/asm-x86/x86_emulate.h

index cb8d40a70eef0098d0bbb269a40e85eab761d2bc..43f90166241c1455952b518cc6d7d14c6b69704c 100644 (file)
@@ -159,7 +159,7 @@ static uint8_t opcode_table[256] = {
     ByteOp|DstMem|SrcImplicit|ModRM, DstMem|SrcImplicit|ModRM, 
     ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
     /* 0xD8 - 0xDF */
-    0, 0, 0, 0, 0, 0, 0, 0,
+    0, ImplicitOps|ModRM, 0, ImplicitOps|ModRM, 0, ImplicitOps|ModRM, 0, 0,
     /* 0xE0 - 0xE7 */
     ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
     ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
@@ -864,7 +864,7 @@ x86_emulate(
     struct cpu_user_regs _regs = *ctxt->regs;
 
     uint8_t b, d, sib, sib_index, sib_base, twobyte = 0, rex_prefix = 0;
-    uint8_t modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0;
+    uint8_t modrm = 0, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0;
     unsigned int op_bytes, def_op_bytes, ad_bytes, def_ad_bytes;
 #define REPE_PREFIX  1
 #define REPNE_PREFIX 2
@@ -2517,6 +2517,36 @@ x86_emulate(
         break;
     }
 
+    case 0xd9: /* FPU 0xd9 */
+        fail_if(ops->load_fpu_ctxt == NULL);
+        ops->load_fpu_ctxt(ctxt);
+        fail_if((modrm_reg & 7) != 7);
+        fail_if(modrm_reg >= 0xc0);
+        /* fnstcw m2byte */
+        ea.bytes = 2;
+        dst = ea;
+        asm volatile ( "fnstcw %0" : "=m" (dst.val) );
+        break;
+
+    case 0xdb: /* FPU 0xdb */
+        fail_if(ops->load_fpu_ctxt == NULL);
+        ops->load_fpu_ctxt(ctxt);
+        fail_if(modrm != 0xe3);
+        /* fninit */
+        asm volatile ( "fninit" );
+        break;
+
+    case 0xdd: /* FPU 0xdd */
+        fail_if(ops->load_fpu_ctxt == NULL);
+        ops->load_fpu_ctxt(ctxt);
+        fail_if((modrm_reg & 7) != 7);
+        fail_if(modrm_reg >= 0xc0);
+        /* fnstsw m2byte */
+        ea.bytes = 2;
+        dst = ea;
+        asm volatile ( "fnstsw %0" : "=m" (dst.val) );
+        break;
+
     case 0xe0 ... 0xe2: /* loop{,z,nz} */ {
         int rel = insn_fetch_type(int8_t);
         int do_jmp = !(_regs.eflags & EFLG_ZF); /* loopnz */
index a794e03d6f389d620742397cecb13e6051a5efd2..17a76f936a9a4d8fe9d2ce304ea0e9ebfa18476f 100644 (file)
@@ -340,6 +340,10 @@ struct x86_emulate_ops
         uint8_t vector,
         uint8_t insn_len,
         struct x86_emulate_ctxt *ctxt);
+
+    /* load_fpu_ctxt: Load emulated environment's FPU state onto processor. */
+    void (*load_fpu_ctxt)(
+        struct x86_emulate_ctxt *ctxt);
 };
 
 struct cpu_user_regs;